package com.qc.toutiao.util;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.lf5.util.Resource;

public class SessionUtil {
	
	
	
	
	public SqlSession getSqlSession() {
		
		SqlSession session=null;
		SqlSessionFactory sf;
		try {
			sf = new SqlSessionFactoryBuilder().build
					(Resources.getResourceAsStream("myBatis.xml"));
			session=sf.openSession();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return session;
	
	}
	
	public void closeSession(SqlSession session){
		
		if(null!=session){
			
			session.commit();
			session.close();
		}
		
		
	}
	
	
	
	

}
